class BaseScene {
    private _layers: Array<egret.DisplayObjectContainer>;

    public constructor() {
        this._layers = new Array<egret.DisplayObjectContainer>();
    }

    public onEnter(): void {

    }

    public onExit(): void {
        App.ViewManager.closeAll()
        this.removeAllLayer()
    }

    public addLayer(layer: egret.DisplayObjectContainer): void {
        if (layer instanceof BaseSpriteLayer) {
            App.StageUtils.getStage().addChild(layer);
            this._layers.push(layer);
        }
        else if (layer instanceof BaseEuiLayer) {
            App.StageUtils.getUIStage().addChild(layer);
            this._layers.push(layer);
        }
    }
    public addLayerAt(layer: egret.DisplayObjectContainer, index: number): void {
        if (layer instanceof BaseSpriteLayer) {
            App.StageUtils.getStage().addChildAt(layer, index);
            this._layers.push(layer);
        }
        else if (layer instanceof BaseEuiLayer) {
            App.StageUtils.getUIStage().addChildAt(layer, index);
            this._layers.push(layer);
        }
    }
    public removeLayer(layer: egret.DisplayObjectContainer): void {
        if (layer instanceof BaseSpriteLayer) {
            App.StageUtils.getStage().removeChild(layer);
            this._layers.splice(this._layers.indexOf(layer), 1);
        }
        else if (layer instanceof BaseEuiLayer) {
            App.StageUtils.getUIStage().removeChild(layer);
            this._layers.splice(this._layers.indexOf(layer), 1);
        }
    }
    public layerRemoveAllChild(layer: egret.DisplayObjectContainer): void {
        if (layer instanceof BaseSpriteLayer) {
            layer.removeChildren();
        }
        else if (layer instanceof BaseEuiLayer) {
            (<BaseEuiLayer>layer).removeChildren();
        }
    }
    public removeAllLayer():void {
        while (this._layers.length) {
            var layer:egret.DisplayObjectContainer = this._layers[0];
            this.layerRemoveAllChild(layer);
            this.removeLayer(layer);
        }
    }
}